import { Redirect } from 'umi';

// https://umijs.org/zh-CN/docs/convention-routing#%E6%9D%83%E9%99%90%E8%B7%AF%E7%94%B1
export default (props: any) => {
  const { isLogin } = useAuth();
  if (isLogin) {
    return <div>{props.children}</div>;
  } else {
    return <Redirect to="/login" />;
  }
};

function useAuth(): { isLogin: any } {
  // let max = 1;
  // let min = 0;
  // let range = max - min;
  // let rand = Math.random();
  // let isLogin = min + Math.round(rand * range) !== min;
  // console.log(isLogin);
  return { isLogin: true };
}
